/*
Copyright 2023 Sangfor Technologies Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package operations

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"net/http"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/runtime"
	"github.com/go-openapi/runtime/middleware"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/validate"
)

// NewGetFaultsParams creates a new GetFaultsParams object
//
// There are no default values defined in the spec.
func NewGetFaultsParams() GetFaultsParams {

	return GetFaultsParams{}
}

// GetFaultsParams contains all the bound params for the get faults operation
// typically these are obtained from a http.Request
//
// swagger:parameters GetFaults
type GetFaultsParams struct {

	// HTTP Request Object
	HTTPRequest *http.Request `json:"-"`

	/*Fault domain for a fault.
	  Max Length: 64
	  Min Length: 2
	  In: query
	*/
	Domain *string
	/*The type of the injected fault.
	  Max Length: 128
	  Min Length: 2
	  Pattern: ^[a-z0-9-]*$
	  In: query
	*/
	FaultType *string
	/*The id generated during fault injected.
	  Max Length: 16
	  Min Length: 16
	  Pattern: ^[a-f0-9]*$
	  In: query
	*/
	ID *string
	/*The start time of fault injection.
	  In: query
	*/
	InjectTime *strfmt.DateTime
	/*The status of injected fault.
	  In: query
	*/
	Status *string
	/*The start time of fault injection.
	  In: query
	*/
	UpdateTime *strfmt.DateTime
}

// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewGetFaultsParams() beforehand.
func (o *GetFaultsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
	var res []error

	o.HTTPRequest = r

	qs := runtime.Values(r.URL.Query())

	qDomain, qhkDomain, _ := qs.GetOK("domain")
	if err := o.bindDomain(qDomain, qhkDomain, route.Formats); err != nil {
		res = append(res, err)
	}

	qFaultType, qhkFaultType, _ := qs.GetOK("fault-type")
	if err := o.bindFaultType(qFaultType, qhkFaultType, route.Formats); err != nil {
		res = append(res, err)
	}

	qID, qhkID, _ := qs.GetOK("id")
	if err := o.bindID(qID, qhkID, route.Formats); err != nil {
		res = append(res, err)
	}

	qInjectTime, qhkInjectTime, _ := qs.GetOK("inject-time")
	if err := o.bindInjectTime(qInjectTime, qhkInjectTime, route.Formats); err != nil {
		res = append(res, err)
	}

	qStatus, qhkStatus, _ := qs.GetOK("status")
	if err := o.bindStatus(qStatus, qhkStatus, route.Formats); err != nil {
		res = append(res, err)
	}

	qUpdateTime, qhkUpdateTime, _ := qs.GetOK("update-time")
	if err := o.bindUpdateTime(qUpdateTime, qhkUpdateTime, route.Formats); err != nil {
		res = append(res, err)
	}
	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

// bindDomain binds and validates parameter Domain from query.
func (o *GetFaultsParams) bindDomain(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: false
	// AllowEmptyValue: false

	if raw == "" { // empty values pass all other validations
		return nil
	}
	o.Domain = &raw

	if err := o.validateDomain(formats); err != nil {
		return err
	}

	return nil
}

// validateDomain carries on validations for parameter Domain
func (o *GetFaultsParams) validateDomain(formats strfmt.Registry) error {

	if err := validate.MinLength("domain", "query", *o.Domain, 2); err != nil {
		return err
	}

	if err := validate.MaxLength("domain", "query", *o.Domain, 64); err != nil {
		return err
	}

	return nil
}

// bindFaultType binds and validates parameter FaultType from query.
func (o *GetFaultsParams) bindFaultType(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: false
	// AllowEmptyValue: false

	if raw == "" { // empty values pass all other validations
		return nil
	}
	o.FaultType = &raw

	if err := o.validateFaultType(formats); err != nil {
		return err
	}

	return nil
}

// validateFaultType carries on validations for parameter FaultType
func (o *GetFaultsParams) validateFaultType(formats strfmt.Registry) error {

	if err := validate.MinLength("fault-type", "query", *o.FaultType, 2); err != nil {
		return err
	}

	if err := validate.MaxLength("fault-type", "query", *o.FaultType, 128); err != nil {
		return err
	}

	if err := validate.Pattern("fault-type", "query", *o.FaultType, `^[a-z0-9-]*$`); err != nil {
		return err
	}

	return nil
}

// bindID binds and validates parameter ID from query.
func (o *GetFaultsParams) bindID(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: false
	// AllowEmptyValue: false

	if raw == "" { // empty values pass all other validations
		return nil
	}
	o.ID = &raw

	if err := o.validateID(formats); err != nil {
		return err
	}

	return nil
}

// validateID carries on validations for parameter ID
func (o *GetFaultsParams) validateID(formats strfmt.Registry) error {

	if err := validate.MinLength("id", "query", *o.ID, 16); err != nil {
		return err
	}

	if err := validate.MaxLength("id", "query", *o.ID, 16); err != nil {
		return err
	}

	if err := validate.Pattern("id", "query", *o.ID, `^[a-f0-9]*$`); err != nil {
		return err
	}

	return nil
}

// bindInjectTime binds and validates parameter InjectTime from query.
func (o *GetFaultsParams) bindInjectTime(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: false
	// AllowEmptyValue: false

	if raw == "" { // empty values pass all other validations
		return nil
	}

	// Format: date-time
	value, err := formats.Parse("date-time", raw)
	if err != nil {
		return errors.InvalidType("inject-time", "query", "strfmt.DateTime", raw)
	}
	o.InjectTime = (value.(*strfmt.DateTime))

	if err := o.validateInjectTime(formats); err != nil {
		return err
	}

	return nil
}

// validateInjectTime carries on validations for parameter InjectTime
func (o *GetFaultsParams) validateInjectTime(formats strfmt.Registry) error {

	if err := validate.FormatOf("inject-time", "query", "date-time", o.InjectTime.String(), formats); err != nil {
		return err
	}
	return nil
}

// bindStatus binds and validates parameter Status from query.
func (o *GetFaultsParams) bindStatus(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: false
	// AllowEmptyValue: false

	if raw == "" { // empty values pass all other validations
		return nil
	}
	o.Status = &raw

	if err := o.validateStatus(formats); err != nil {
		return err
	}

	return nil
}

// validateStatus carries on validations for parameter Status
func (o *GetFaultsParams) validateStatus(formats strfmt.Registry) error {

	if err := validate.EnumCase("status", "query", *o.Status, []interface{}{"injected", "removed", "succeeded"}, true); err != nil {
		return err
	}

	return nil
}

// bindUpdateTime binds and validates parameter UpdateTime from query.
func (o *GetFaultsParams) bindUpdateTime(rawData []string, hasKey bool, formats strfmt.Registry) error {
	var raw string
	if len(rawData) > 0 {
		raw = rawData[len(rawData)-1]
	}

	// Required: false
	// AllowEmptyValue: false

	if raw == "" { // empty values pass all other validations
		return nil
	}

	// Format: date-time
	value, err := formats.Parse("date-time", raw)
	if err != nil {
		return errors.InvalidType("update-time", "query", "strfmt.DateTime", raw)
	}
	o.UpdateTime = (value.(*strfmt.DateTime))

	if err := o.validateUpdateTime(formats); err != nil {
		return err
	}

	return nil
}

// validateUpdateTime carries on validations for parameter UpdateTime
func (o *GetFaultsParams) validateUpdateTime(formats strfmt.Registry) error {

	if err := validate.FormatOf("update-time", "query", "date-time", o.UpdateTime.String(), formats); err != nil {
		return err
	}
	return nil
}
